selection model: Add sanity checks
authorMatthias Clasen <mclasen@redhat.com>
Wed, 13 Feb 2019 13:38:30 +0000 (08:38 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 13 Feb 2019 13:38:30 +0000 (08:38 -0500)
It is easy to emit wrong ::selection-changed signals,
and then bad things will usually happen later. Add
some sanity checks to gtk_selection_model_selection_changed
to make this easier to track down.

gtk/gtkselectionmodel.c

index 0be3961bc26edb05c5730f74b53900453bf1db04..137928c68777d6795b8e6b27f51908dcc631ceb6 100644 (file)
@@ -295,6 +295,8 @@ gtk_selection_model_selection_changed (GtkSelectionModel *model,
                                        guint              n_items)
 {
   g_return_if_fail (GTK_IS_SELECTION_MODEL (model));
+  g_return_if_fail (n_items > 0);
+  g_return_if_fail (position + n_items <= g_list_model_get_n_items (G_LIST_MODEL (model)));
 
   g_signal_emit (model, signals[SELECTION_CHANGED], 0, position, n_items);
 }